﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;

namespace game
{
    class opr_game1
    {
        public string sql;
        public static string connStr = "server=.;database=game1;Integrated Security=true";
        /*
         * 增加操作
         * 参数：Sql
         * 返回值：bool
         */
        public static bool GetNonQuery(string Sql)
        {
            bool result = false;
            SqlConnection conn = new SqlConnection(connStr);
            conn.Open();
            SqlCommand cmd = new SqlCommand(Sql, conn);
            int i = cmd.ExecuteNonQuery();
            conn.Close();
            return i > 0;
        }
        /*
         * 查询操作
         * 参数：Sql
         * 返回值：SqlDataReader
         */
        public static SqlDataReader Select(string Sql)
        {
            //1.创建连接对象
            SqlConnection conn = new SqlConnection(connStr);
            //2.打开连接
            conn.Open();
            //3.创建对象命令
            SqlCommand cmd = new SqlCommand(Sql, conn);
            //4.ExecuteReader执行
            return cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
        }/*
         * 集合函数操作
         * 参数：Sql
         * 返回值：object
         */
        public static object ExecuuteScalar(string Sql)
        {
            //1.创建连接对象
            SqlConnection conn = new SqlConnection(connStr);
            //2.打开连接
            conn.Open();
            //3.创建对象命令
            SqlCommand cmd = new SqlCommand(Sql, conn);
            object result = cmd.ExecuteScalar();
            conn.Close();
            return result;
        }
    }
}
